package com.example.gradle_test_css.controller;

import com.example.gradle_test_css.Entity.Menutable;
import com.example.gradle_test_css.repository.MenutableRepository;
import com.example.gradle_test_css.server.MenuTableServer;
import javafx.scene.input.Mnemonic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Controller
public class baiscController {

    @Autowired
    private MenuTableServer menuTableServer;


    @GetMapping("/master")
    public String getmain(Model model){
        List<Menutable> menutableList = menuTableServer.menulist();
        List<Menutable> newmenutablep = new ArrayList<>();
        for (Menutable menutablep:menutableList){
            Menutable menutable = new Menutable();
            menutable.setId(menutablep.getId());
            menutable.setUrl(menutablep.getUrl());
            menutable.setName(menutablep.getName());
            List<Menutable> newmenutablec = new ArrayList<>();
            for (Menutable menutablec : menutablep.getMenus()){
                Menutable menutable2 = new Menutable();
                menutable2.setId(menutablec.getId());
                menutable2.setUrl(menutablec.getUrl());
                menutable2.setName(menutablec.getName());
                newmenutablec.add(menutable2);
            }
            menutable.setMenus(newmenutablec);
            newmenutablep.add(menutable);
        }
        model.addAttribute("menus",newmenutablep);
        return "master";
    }
    @GetMapping("/index")
    public String getindex(){
        return "index";
    }

    @GetMapping("/userindex")
    public String getuserindex(){
        return "basic/userindex";
    }
}
